#define _CRT_SECURE_NO_WARNINGS 1

class BrowserHistory {
public:
    BrowserHistory(string homepage) {
        _stay = homepage;
    }

    void visit(string url) {
        while (_back_history.size())
        {
            _back_history.pop();
        }
        _history.push(_stay);
        _stay = url;
    }

    string back(int steps) {
        while (_history.size() && steps--)
        {
            _back_history.push(_stay);
            _stay = _history.top();
            _history.pop();
        }
        return _stay;
    }

    string forward(int steps) {
        while (_back_history.size() && steps--)
        {
            _history.push(_stay);
            _stay = _back_history.top();
            _back_history.pop();
        }
        return _stay;
    }
private:
    string _stay;
    stack<string> _history;
    stack<string> _back_history;
};

/**
 * Your BrowserHistory object will be instantiated and called as such:
 * BrowserHistory* obj = new BrowserHistory(homepage);
 * obj->visit(url);
 * string param_2 = obj->back(steps);
 * string param_3 = obj->forward(steps);
 */